package com.atguigu.mall.search.controller;

import com.atguigu.mall.search.service.MallService;
import com.atguigu.mall.search.vo.SearchParam;
import com.atguigu.mall.search.vo.SearchResult;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;

import javax.servlet.http.HttpServletRequest;

/**
 * @author lirl
 * @date 2021/2/19 23:33
 * 检索服务
 */
@Controller
@Slf4j
public class SerachController {
    @Autowired
    private MallService mallService;
    @GetMapping("/list.html")
    public String list(SearchParam searchParam, Model model, HttpServletRequest request){
        String queryString = request.getQueryString();
        searchParam.set_queryString(queryString);
        SearchResult result = mallService.search(searchParam);
        model.addAttribute("result", result);
        return "list";
    }

}
